//
// Created by root on 05/04/17.
//

#include <common.hpp>
#include "pack_meta_svr_api.h"
/*4.6 优化，只取常规表，提高效率*/
PackMetaSvrApiGetRecentMeta::PackMetaSvrApiGetRecentMeta(Poco::Event &ev, std::set<meta::MetaStruct> &metas,string busi_type, string uid, bool order_asc, unsigned long limit, string staff_id):_ev(ev),_metas(metas) {

    _busi_type=busi_type;
    _uid=uid;
    _order_asc=order_asc;
    _limit=limit;
    _staff_id=staff_id;
}
void PackMetaSvrApiGetRecentMeta::run() {

    int count=0;
    for (int i = 0; i < QUERY_DAYS; i++) {
        string beg_time = common::DateTime::CurMysqlDateBeforeSecStr(i * 3600 * 24);
        beg_time.append(" 00:00:00");
        string end_time = common::DateTime::CurMysqlDateBeforeSecStr(i * 3600 * 24);
        end_time.append(" 23:59:59");
        int ret = meta_svr::MetaSvrInterface::SingletonInstance().GetMeta(_metas, beg_time, end_time,_busi_type,_uid,"1,2,4", false, _limit+2);
        if (ret < 0) {
            printf("get meta error\n");
        } else {
            count += ret;
        }
        if (count >= _limit)
            break;
    }
    _ev.set();
}


PackMetaSvrApiGetGeneralMeta::PackMetaSvrApiGetGeneralMeta(Poco::Event &ev, std::set<meta::MetaStruct> &metas,
                                                           string busi_type, string uid, string beg_time,
                                                           string end_time, string staff_id):_ev(ev),_metas(metas) {
    _busi_type=busi_type;
    _uid=uid;
    _beg_time=beg_time;
    _end_time=end_time;
    _staff_id=staff_id;
}

void PackMetaSvrApiGetGeneralMeta::run() {

    int count=0;
    for (int i = 0; i < QUERY_DAYS; i++) {
        int ret = meta_svr::MetaSvrInterface::SingletonInstance().GetMeta(_metas, _beg_time, _end_time,_busi_type,_uid,"all", false, 0);
        if (ret < 0) {
            printf("get meta error\n");
        } else {
            count += ret;
        }
    }
    _ev.set();
}